<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
楼盘状态 <select name="status">
    <option value="入住">入住</option>
    <option value="在售">在售</option>
    <option value="停工">停工</option>
</select>

<input type="button" value="点击展示柱状图" onclick="zzt()">
<input type="button" value="点击导出excel" onclick="excel()">
<div id="main" style="height: 600px;width: 600px;"></div>

</body>


<script>

    function excel() {
        let status = $('[name=status]').val();

        location.href = 'excelCount.do?status=' + status
    }

    function zzt() {
        let status = $('[name=status]').val();

        $.ajax({
            url: 'zzt.do?status=' + status,

            success: function (data) {

                console.log(data)

                var x = [];
                var y = [];
                // 找到y轴的最大值
                let maxY = data[0].ydata;
                for (let i = 0; i < data.length; i++) {
                    let xdata = data[i].xdata;
                    x.push(xdata)
                    let ydata = data[i].ydata;
                    if (ydata == maxY) {
                        y.push({
                            value: ydata,
                            itemStyle: {
                                color: '#a90000'
                            }
                        })
                    } else {
                        y.push(ydata)
                    }


                }

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'bar'
                        }
                    ]
                };

                option && myChart.setOption(option);


            }
        })
    }


</script>
</html>